import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { getRangePickerDefaultProps } from '#/utils';
import { $t } from '#/locales';

/** 表单的字段 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'file',
      label: $t('views.infra.file.file'),
      component: 'Upload',
      componentProps: {
        placeholder: $t('views.infra.file.filePlaceholder'),
      },
      rules: 'required',
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'path',
      label: $t('views.infra.file.path'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.infra.file.pathPlaceholder'),
        clearable: true,
      },
    },
    {
      fieldName: 'type',
      label: $t('views.infra.file.type'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.infra.file.typePlaceholder'),
        clearable: true,
      },
    },
    {
      fieldName: 'createTime',
      label: $t('views.infra.file.createTime'),
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'name',
      title: $t('views.infra.file.name'),
      minWidth: 150,
    },
    {
      field: 'path',
      title: $t('views.infra.file.path'),
      minWidth: 200,
      showOverflow: true,
    },
    {
      field: 'url',
      title: $t('views.infra.file.url'),
      minWidth: 200,
      showOverflow: true,
    },
    {
      field: 'size',
      title: $t('views.infra.file.size'),
      minWidth: 80,
      formatter: 'formatFileSize',
    },
    {
      field: 'type',
      title: $t('views.infra.file.type'),
      minWidth: 120,
    },
    {
      field: 'file-content',
      title: $t('views.infra.file.fileContent'),
      minWidth: 120,
      slots: {
        default: 'file-content',
      },
    },
    {
      field: 'createTime',
      title: $t('views.infra.file.createTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('common.action'),
      width: 160,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
